package consume;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import utils.RabbitMqUtils;

import java.io.IOException;

public class FederationExchange {
    //路由名称
    private static final String EXCHANGE = "fed_exchange";

    public static void main(String[] args) {
        //获取通道
        Channel channel = RabbitMqUtils.getChannel();
        try {
            //声明交换机
            channel.exchangeDeclare(EXCHANGE, BuiltinExchangeType.DIRECT);
            channel.queueDeclare("node2_queue", true, false, false, null);
            channel.queueBind("node2_queue", EXCHANGE, "routeKey");

            /**
             //声明临时队列
             String queue = channel.queueDeclare().getQueue();
             channel.queueBind(queue, EXCHANGE, "google");
             //消费消息
             DeliverCallback deliverCallback = (consumerTag, message) -> {
             System.out.println(new String(message.getBody()));
             };
             CancelCallback cancelCallback = consumerTag -> {
             System.out.println("消息消费异常");
             };
             System.out.println("ConsumerA准备就绪");
             channel.basicConsume(queue, true, deliverCallback, cancelCallback);
             */
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
